// 定义一个抽象的动物类
class Animal {
    constructor(name, type, breed, price) {
        if (new.target === Animal) {
            throw new Error("无法直接实例化抽象类 Animal");
        }
        this.name = name;
        this.type = type;
        this.breed = breed;
        this.price = price;
    }

    eat() {
        console.log(`${this.name} 正在吃东西`);
    }

    sleep() {
        console.log(`${this.name} 正在睡觉`);
    }

    play() {
        console.log(`${this.name} 正在玩耍`);
    }

    sound() {
        console.log(`${this.name} 发出叫声`);
    }
}

// 定义小猫子类
class Cat extends Animal {
    constructor(name, breed, price) {
        super(name, "猫", breed, price);
    }

    play() {
        super.play();
        this.sound();  // 只有在玩的情况下才会叫
    }

    sound() {
        console.log(`${this.name} 喵喵叫`);
    }
}

// 定义小狗子类
class Dog extends Animal {
    constructor(name, breed, price) {
        super(name, "狗", breed, price);
    }

    sound() {
        console.log(`${this.name} 汪汪叫`);
    }
}

// 实例化两个小猫对象
const cat1 = new Cat("小花", "波斯猫", 3000);
const cat2 = new Cat("小白", "英短猫", 3500);

// 实例化两个小狗对象
const dog1 = new Dog("旺财", "哈士奇", 4000);
const dog2 = new Dog("小黑", "拉布拉多", 4500);

// 调用各个对象的方法
cat1.eat();
cat1.sleep();
cat1.play();  // 只有在玩的时候才会喵喵叫

dog1.eat();
dog1.sleep();
dog1.sound();  // 狗可以随时汪汪叫
